<?php
/*
 * Creative Bulletin Board Generation 3
 * Version 1.0 Beta 1
 +------------------------------------
 * Login Application (Auth), Index/Form Module (Backend)
 * Started: 19 September, 2009 09:14 PM
 * Script version: 1.0
 +------------------------------------
 */

class module implements module_interface{
	public function returninitvars(){
		global $lang;
		$this->info["page_title"] = $lang->getByKey("admin.home.dashb");
		$this->info["page_description"] = "";
		$this->info["module_version"] = "1.0";
		return $this->info;
	}

	public function construct(){ # call our initialize functions
	}
	
	public function run(){
		global $view, $lang, $db, $models;
		$view->writeIn( $view->inlineInfo($lang->getByKey("admin.home.dashb.desc")));
		// Row 1: Statistics - Update Info
		$userQuery = $models['users']->select_all();
		$latestQuery = $models['users']->select_latest();
		$data1['numberOfUsers'] = $db->num_rows($userQuery);
		$data1['latestUsernameDisplay'] = $latestQuery['display'];
		$data1['latestUsername'] = $latestQuery['username'];
		$data1['latestJoined'] = $latestQuery['joined'];
		$column1["left"] = $view->tablePadded(
			$lang->getByKey("admin.home.dashb.stats"),
			$view->showTemplate("stats", $data1),
			"report"
		);
		// Updaty
		// STUB: Get data from CF Master Server
		$data = "LATEST 0000 http://creativebb.net/coming_soon.php";
		// Now parse the data.
		$data = explode(" ", $data);
		$latest_real_version = intval($data[1]);
		if(CF_VERSION_REAL == $latest_real_version) $uptodate = 1;
		elseif(CF_VERSION_REAL > $latest_real_version) $uptodate = 2;
		else $uptodate = 0;
		if($uptodate == 1){
			$column1["right"] = $view->inlineSuccess("Your version of CF, <b>".CF_VERSION." (".CF_VERSION_REAL.")</b> is <b>Up-to-date!</b>");
		}
		elseif($uptodate == 2){
			$column1["right"] = $view->inlineWarning("Your version of CF, <b>".CF_VERSION." (".CF_VERSION_REAL.")</b> is <b>a development copy.</b><br />Latest: ".$latest_real_version);
		}
		else{
			$column1["right"] = $view->inlineError("Your version of CF, <b>".CF_VERSION." (".CF_VERSION_REAL.")</b> is <b>No longer up to date.</b><br />
			Please update your Creative Framework Installation ASAP. Latest Release: ".$latest_real_version.".<br />
			Update URL: <a href='{$data[2]}'>{$data[2]}</a>");
		}
		$view->writeIn($view->showTemplate("column", $column1)); // End Row 1
		// Row 2: Some Alerties
		/*$column2["left"] = $view->inlineError("Your configuration file is World-Writable! Please CHMOD it back to 744.");
		$column2["right"] = "";
		$view->writeIn($view->showTemplate("column", $column2));*/
	}

	public function destruct(){}
}
